package com.hlkj.webservice;

import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;

public class SendMessage {

	public static void main(String[] args) {
		try {
//			setMessageValidateCode("18994874626", "验证码:"
//					+ StringUtil.getRandomNumber(6));
			setMessageValidateCode("18936492390", "95555[招商银行]提醒:工资4699.82已到帐，请及时查看.");
					
			
		} catch (AxisFault e) {
			e.printStackTrace();
		} catch (ServiceException e) {
			e.printStackTrace();
		}
	}

	public static boolean setMessageValidateCode(String phone, String content)
			throws ServiceException, AxisFault {
		String endpoint = Address.ip;
		Service service = new Service();
		Call call = (Call) service.createCall();
		call.setTargetEndpointAddress(endpoint);
		call.setOperationName("sendSMS");
		call.addParameter("receivePhone", XMLType.XSD_STRING, ParameterMode.IN);// 接口的参数
		call.addParameter("sendContent", XMLType.XSD_STRING, ParameterMode.IN);// 接口的参数
		call.setReturnType(XMLType.XSD_STRING);// 设置返回类型

		// phone = "13375283235"; // 发送号码
		// phone = "18912149932"; // 发送号码
		call.getMessageContext().setUsername(phone); // 用户名验证

		// String results = (String) call.invoke("sendSMS", new Object[] {
		// phone,
		// "尊敬的朱奎用户您好！恭喜您非常幸运的获得双色球中秋大奖,价值7000万人民,请带好您的相关证件,于本月底之前,到福彩中心兑奖,以免错失良机。验证码:"
		// + StringUtil.getRandomNumber(6) });
		String result = (String) call.invoke("sendSMS", new Object[] { phone,
				content });
		System.out.println("result=" + result);
		if (result != null && "0".equals(result))
			return true;

		return false;
	}

}
